package com.zhxh.nzpos.buyin;

import java.util.ArrayList;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhxh.nzpos.R;
import com.zhxh.nzpos.model.Buyin;

public class ConfirmListAdapter extends BaseAdapter {

	private ArrayList<Buyin> items;
	private LayoutInflater inflater;
	
	public ConfirmListAdapter(LayoutInflater inflater, ArrayList<Buyin> dealItems) {
		this.items = dealItems;
		this.inflater = inflater;
	}
	
	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.buyin_confirm_list_item, null);
			holder = new ViewHolder();
			holder.identifier = (TextView) convertView.findViewById(R.id.buyin_confirm_identifier_et);
			holder.name = (TextView) convertView.findViewById(R.id.buyin_confirm_name_et);
			holder.sum = (TextView) convertView.findViewById(R.id.buyin_confirm_number_et);
			holder.unitPrice = (TextView) convertView.findViewById(R.id.buyin_confirm_unit_price_et);
			holder.money = (TextView) convertView.findViewById(R.id.buyin_comfirm_sum_money_et);
			holder.buyinDate = (TextView) convertView.findViewById(R.id.buyin_date_et);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		Buyin item = items.get(position);
		if (item != null) {
			holder.identifier.setText(item.getGoodId());
			holder.name.setText(item.getName());
			holder.sum.setText(""+item.getCount());
			holder.unitPrice.setText(""+item.getPrice());
			holder.money.setText(""+item.getTotal());
			holder.buyinDate.setText(item.getBuyinDate());
		}
		return convertView;
	}

	static class ViewHolder {
		TextView identifier;
		TextView name;
		TextView sum;
		TextView unitPrice;
		TextView money;
		TextView buyinDate;

	}
}
